package com.zhifa.hdtyg_cdgl.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhifa.hdtyg_cdgl.dao.SiteReservationMapper;
import com.zhifa.hdtyg_cdgl.entity.SiteReservation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SiteReservationService {

    @Autowired
    private SiteReservationMapper siteReservationMapper;

    public int addSiteReservation(SiteReservation siteReservation){
        return siteReservationMapper.insert(siteReservation);
    }

    public List<SiteReservation> findWhemTime(Integer site_id,Date application_time){
        Map<String, Object> map = new HashMap<>();
        map.put("site_id",site_id);
        map.put("application_time",application_time);
        return siteReservationMapper.findWhentime(map);
    }

    public PageInfo<SiteReservation> findMySiteReservation(SiteReservation siteReservation, int page, int rows){

        PageHelper.startPage(page, rows);
        List<SiteReservation> mySiteReservation = siteReservationMapper.findMySiteReservation(siteReservation);
        PageInfo<SiteReservation>pageInfo=new PageInfo<>(mySiteReservation);
        return  pageInfo;
    }

    public List<String>findStatus(){
        List<String> status = siteReservationMapper.findStatus();
        return  status;
    }

    public int changeMyYuyueSatus(SiteReservation siteReservation){
        return siteReservationMapper.changeMyYuyueSatus(siteReservation);
    }

    public PageInfo<SiteReservation> findAllSiteReservation(SiteReservation siteReservation, int page, int rows){
        PageHelper.startPage(page, rows);

        List<SiteReservation> allSiteReservation = siteReservationMapper.findAllSiteReservation(siteReservation);
        PageInfo<SiteReservation>pageInfo=new PageInfo<SiteReservation>(allSiteReservation);
        return  pageInfo;

    }
    public SiteReservation findSiteReservation(SiteReservation siteReservation){
        return siteReservationMapper.findSiteReservation(siteReservation);
    }

    @Transactional
    public int modifyShenqingZhuangtai(SiteReservation siteReservation){
        int i = siteReservationMapper.updateStatusBysiteYyId(siteReservation.getSiteYyId());
        int i1 = siteReservationMapper.updateStatusByApplicationTimeAndWhenTime(siteReservation);

        return i;
    }

}
